package com.estacionamientos

class OperacionVigenteController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

	def operacionVigenteService
    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [operacionVigenteInstanceList: OperacionVigente.list(params), operacionVigenteInstanceTotal: OperacionVigente.count()]
    }

    def create = {
        def operacionVigenteInstance = new OperacionVigente()
        operacionVigenteInstance.properties = params
        return [operacionVigenteInstance: operacionVigenteInstance]
    }

    def save = {
        def operacionVigenteInstance = new OperacionVigente(params)
        if (operacionVigenteService.saveObj(operacionVigenteInstance)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'operacionVigente.label', default: 'OperacionVigente'), operacionVigenteInstance.id])}"
            redirect(action: "show", id: operacionVigenteInstance.id)
        }
        else {
            render(view: "create", model: [operacionVigenteInstance: operacionVigenteInstance])
        }
    }

    def show = {
        def operacionVigenteInstance = operacionVigenteService.getObj(params.id)
        if (!operacionVigenteInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'operacionVigente.label', default: 'OperacionVigente'), params.id])}"
            redirect(action: "list")
        }
        else {
            [operacionVigenteInstance: operacionVigenteInstance]
        }
    }

    def edit = {
        def operacionVigenteInstance = operacionVigenteService.getObj(params.id)
        if (!operacionVigenteInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'operacionVigente.label', default: 'OperacionVigente'), params.id])}"
            redirect(action: "list")
        }
        else {
            return [operacionVigenteInstance: operacionVigenteInstance]
        }
    }

    def update = {
        def operacionVigenteInstance = operacionVigenteService.getObj(params.id)
        if (operacionVigenteInstance) {
            if (params.version) {
                def version = params.version.toLong()
                if (operacionVigenteInstance.version > version) {
                    
                    operacionVigenteInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'operacionVigente.label', default: 'OperacionVigente')] as Object[], "Another user has updated this OperacionVigente while you were editing")
                    render(view: "edit", model: [operacionVigenteInstance: operacionVigenteInstance])
                    return
                }
            }
            operacionVigenteInstance.properties = params
            if (!operacionVigenteInstance.hasErrors() && operacionVigenteService.saveObj(operacionVigenteInstance)) {
                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'operacionVigente.label', default: 'OperacionVigente'), operacionVigenteInstance.id])}"
                redirect(action: "show", id: operacionVigenteInstance.id)
            }
            else {
                render(view: "edit", model: [operacionVigenteInstance: operacionVigenteInstance])
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'operacionVigente.label', default: 'OperacionVigente'), params.id])}"
            redirect(action: "list")
        }
    }

    def delete = {
        def operacionVigenteInstance = operacionVigenteService.getObj(params.id)
        if (operacionVigenteInstance) {
            try {
                operacionVigenteService.deleteObj(operacionVigenteInstance)
                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'operacionVigente.label', default: 'OperacionVigente'), params.id])}"
                redirect(action: "list")
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'operacionVigente.label', default: 'OperacionVigente'), params.id])}"
                redirect(action: "show", id: params.id)
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'operacionVigente.label', default: 'OperacionVigente'), params.id])}"
            redirect(action: "list")
        }
    }
}
